package homework;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import cn.hutool.core.io.FileUtil;

public class Work6 {
	public static void main(String[] args) throws Exception {
		ArrayList<Student6> list = new ArrayList<>();
		List<String> line = FileUtil.readLines("..\\work6.txt", "GBK");
		List<Student6> collect = line.stream().map(s -> new Student6(s.split("-")[0], s.split("-")[1],Integer.parseInt(s.split("-")[2]), Integer.parseInt(s.split("-")[3]))).collect(Collectors.toList());
		boolean flag = true;
		for (Student6 student : collect) {
			if (student.getState() == 0) {
				list.add(student);
				flag = false;
			}
		}
		if (flag) {
			list.addAll(collect);
			for (Student6 student : collect) {
				student.setState(0);
			}
		}
		int result = new Random().nextInt(list.size());
		System.out.println(
				list.get(result).getName() + "-" + list.get(result).getGender() + "-" + list.get(result).getAge());
		for (Student6 student : collect) {
			if (student.equals(list.get(result))) {
				student.setState(1);
			}
		}
		FileUtil.writeLines(collect, "..\\work6.txt", "GBK");

	}
}
